new Vue({
  el: "#app",
  data() {
    return {
      rules: {
        Company_Profile_Name: [
          { required: true, message: "请输入简介说明", trigger: "blur" },
        ],
        Company_Profile_Main: [
          { required: true, message: "请输入简介内容", trigger: "blur" },
        ],
      },
      form: {
        Company_Profile_SerialNumber: "",
        Company_Profile_Name: "",
        Company_Profile_Date: "",
        Company_Profile_Main: "",
      },
      loading: false,
    };
  },
  mounted() {
    const Company_Profile_SerialNumber = sessionStorage.getItem(
      "Company_Profile_SerialNumber"
    );
    console.log(Company_Profile_SerialNumber);

    this.getData(Company_Profile_SerialNumber);
  },
  methods: {
    getData(Primary_Key) {
      const _this = this;
      $.ajax({
        // url: DomainName + "/getInquiryIDOriginal?token=" + $.cookie("token"),
        url: " https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        type: "POST",
        data: {
          Data: "company_profile", //表名
          Condition: "Company_Profile_SerialNumber='" + Primary_Key + "'",
        },
        success: function (res) {
          console.log(res);

          if (res.length > 0) {
            _this.form = res[0];
          }
        },
        error: function () {
          _this.$message.error("操作失败，请稍后再试");
        },
        // complete: function (XMLHttpRequest) {
        //     _this.loading = false
        //     if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //         window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //     }
        // }
      });
    },
    submitForm(formName) {
      console.log(this.form);
      let lArray = new Array();
      lArray.push(this.form);
      let lJSONObject_company_profile = new Object();
      lJSONObject_company_profile.company_profile = lArray; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Modify = lJSONObject_company_profile; //换表
      console.log(lJSONObject_DataSet);

      let _this = this;
      $.ajax({
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "success") {
            _this.$message({
              message: "提交成功",
              type: "success",
            });
            window.history.go(-1);
          } else {
            _this.$message.error("提交失败，请稍后再试");
          }
        },
        // complete: function (XMLHttpRequest) {
        //   requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        // },
        dataType: "json",
      });
      //   this.$refs[formName].validate((valid) => {
      //     if (valid) {
      //       _this.loading = true;
      //       const { add, modify } = _this.deal();
      //       let data = {};
      //       if (add == null) {
      //         data = {
      //           Data: JSON.stringify({ Modify: { company_profile: [modify] } }),
      //         };
      //       } else {
      //         data = {
      //           Data: JSON.stringify({
      //             Modify: { company_profile: [modify] },
      //             Add: { company_profile: [add] },
      //           }),
      //         };
      //       }
      //       $.ajax({
      //         url: DomainName + "/getEditAction?token=" + $.cookie("token"),
      //         type: "POST",
      //         data: { ...data, Operation_Name: "修改公司简介" },
      //         success: function (res) {
      //           if (res.Status === "success") {
      //             _this.$message.success("提交成功");
      //             window.history.go(-1);
      //           } else {
      //             _this.$message.error("提交失败，请稍后再试");
      //           }
      //         },
      //         error: function () {
      //           _this.$message.error("操作失败，请稍后再试");
      //         },
      //         // complete: function (XMLHttpRequest) {
      //         //   _this.loading = false;
      //         //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
      //         //     window.parent.document.location.href =
      //         //       absolutepath() +
      //         //       XMLHttpRequest.getResponseHeader("CONTENTPATH");
      //         //   }
      //         // },
      //       });
      //     } else {
      //       return false;
      //     }
      //   });
    },
    deal() {
      const modify = deepClone(this.form);
      return { add: null, modify };
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
});
